package com.hustmed.utils;

import com.hustmed.domain.Material;
import com.ruoyi.common.utils.StringUtils;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

import java.lang.reflect.Method;

public class MySqlScriptProvider implements ProviderMethodResolver {

    public Object invoke(Object target, Method method, Object[] args) throws Throwable {
        // 获取传入的条件参数
        Material material = (Material)args[0];

        StringBuilder sqlBuilder = new StringBuilder();
        if (!StringUtils.isEmpty(material.getVjsonq())) {
            sqlBuilder.append("<where>");

            // 构造动态SQL片段
            sqlBuilder.append("<if test=\"condition != null and !''.equals(condition)\">");
            sqlBuilder.append("AND name LIKE CONCAT('%', #{condition}, '%')");
            sqlBuilder.append("</if>");

            sqlBuilder.append("</where>");
        }

        return "SELECT * FROM user" + sqlBuilder;
    }

}